#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include "Player.h"

#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923

Player::Player(){};

Player::~Player(){};

void Player::Init(float x, float y, float z, float limit, float psize){
	this->x = x;
	this->y = y;
	this->z = z;

	this->limit = limit;
	player_size = psize;
}

void Player::UpdatePlayerSize(float size)
{
	player_size = size;
}

void Player::Update(){
	lz = cos(yaw);
	lx = sin(yaw);

	strafe_lz = cos(yaw - M_PI_2);
	strafe_lx = sin(yaw - M_PI_2);
}

float Player::getX()
{
	return x;
}

float Player::getY()
{
	return y;
}

float Player::getZ()
{
	return z;
}

float Player::getFace()
{
	return (facing/(2*M_PI))*360;
}

float Player::get_player_size()
{
	return player_size;
}

void Player::MoveFrontBack(int direction)
{
	float tempx = x + direction*(lx)*INCR;
	if(tempx >= 0 && tempx <= limit - player_size)
		x = tempx;

	float tempz = z + direction*(lz)*INCR;
	if(tempz >= 0 && tempz <=limit - player_size)
		z = tempz;

	Update();
}

void Player::MoveLeftRight(int direction)
{
	float tempx = x + direction*(strafe_lx)*INCR;
	if(tempx >= 0 && tempx <= limit - player_size)
		x = tempx;

	float tempz =  z + direction*(strafe_lz)*INCR;
	if(tempz >= 0 && tempz <= limit - player_size)
		z = tempz;

	Update();
}

void Player::RotateFace(float angle)
{
	facing = angle*ROTATION_SPEED;
}

void Player::SetX(float i) {x = i;}

void Player::SetZ(float i) {z = i;}

const float Player::INCR = 0.25;
const float Player::ROTATION_SPEED = M_PI_2;